package com.bb.blog.biz.manage.controller;

import com.bb.blog.biz.manage.service.SysMenuService;
import com.bb.blog.security.resource.SecurityUtils;
import com.bb.blog.web.component.ResponseUtil;
import com.bb.blog.web.model.CommonResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import org.springframework.security.oauth2.core.AbstractOAuth2Token;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.server.resource.authentication.AbstractOAuth2TokenAuthenticationToken;
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class UserInfoController {
    private final SysMenuService sysMenuService;
    /**
     * 用户信息 +　resource + menu
     * @return
     */

    @GetMapping("/userInfo")
    @SuppressWarnings("unchecked")
    public CommonResponse<Object> userInfo(){
        Map<String, Object> result = new HashMap<>();
        // 先进行一个类型转换 todo  resources 包下  变成工具类

        HashMap<String,Object> userAddition = new HashMap<>();
        userAddition.put("id", SecurityUtils.loadUserId());
        userAddition.put("username", SecurityUtils.loadUsername());

        result.put("menuList", sysMenuService.menuList(null, null , null) );
        result.put("userInfo", userAddition);

        return ResponseUtil.success(result);
    }
}
